package com.mdp.workflow.bus.candidate.strategy;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
import com.mdp.workflow.bus.candidate.TaskCandidateStrategy;
import com.mdp.workflow.comm.tools.FlowableUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 流程表达式 {@link TaskCandidateStrategy} 实现类
 *
 *@author 唛盟开源9哥
 */
@Component
public class ExpressionStrategy implements TaskCandidateStrategy {

    @Override
    public com.mdp.workflow.comm.dict.CandidateStrategy getStrategy() {
        return com.mdp.workflow.comm.dict.CandidateStrategy.EXPRESSION;
    }

    @Override
    public void validateParam(String param) {
        Assert.notNull(param,"表达式不能为空");

    }

    @Override
    public Set<String> calculateUsers(DelegateExecution execution, String param) {
        Object result = FlowableUtils.getExpressionValue(execution, param);
        return Convert.toSet(String.class, result);
    }

}